package com.biaobiaoqi.scoreanalysis.administrator.action;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.biaobiaoqi.scoreanalysis.exception.DuplicateTeacherException;
import com.biaobiaoqi.scoreanalysis.service.ITeacherService;
import com.opensymphony.xwork2.ActionSupport;

public class AddTeacher extends ActionSupport {
	private static final Log log = LogFactory.getLog(AddTeacher.class);
	private static final long serialVersionUID = 7462785304627554383L;
	private String loginName;
	private String password;
	private String confirmPassword;
	private String email;
	private String phone;
	private String gender;
	private String birthday;
	@Resource
	private ITeacherService teacherService;

	public String execute() {
		log.debug("loginName:" + loginName + " password:" + password
				+ "confirmPassword:" + confirmPassword + " email:" + email
				+ " phone:" + phone + " gender:" + gender + " birthday:"
				+ birthday);
		System.out.println("loginName:" + loginName + " password:" + password
				+ "confirmPassword:" + confirmPassword + " email:" + email
				+ " phone:" + phone + " gender:" + gender + " birthday:"
				+ birthday);
		try {
			if (!password.equals(confirmPassword)) {
				addActionError("两次密码输入不符！");
				return ERROR;
			}
			teacherService.addTeacher(loginName, confirmPassword, gender,
					birthday, phone, email);
			return SUCCESS;
		} catch (DuplicateTeacherException e) {
			addActionError("用户名已存在");
			log.debug("用户名已存在", e);
			return INPUT;
		} catch (Exception e) {
			addActionError("服务器内部错误");
			log.error("服务器内部错误", e);
			e.printStackTrace();
			return ERROR;
		}
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public ITeacherService getTeacherService() {
		return teacherService;
	}

	public void setTeacherService(ITeacherService teacherService) {
		this.teacherService = teacherService;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}
}
